package com.yuyue.springFramework.note17.examp2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 服务类
 */
@Component
public class AnnoPersonService1 {
    @Autowired
    private AnnoPersonDao personDao;

    @Transactional
    //正常的事务
    public void test1(Person person){
        //插入表
        personDao.insertTable(person);

        //报错
        System.out.println(1/0);
    }

    @Transactional
    //修饰符非public
    protected void test2(Person person){
        //插入表
        personDao.insertTable(person);

        //报错
        System.out.println(1/0);
    }

    //public修饰，用于调用带事务非public方法
    public void test3(Person person){
        test2(person);
    }

    //查询
    @Transactional(readOnly = true)
    public List<Map<String, Object>> queryOneObjectList(String id){
        return  personDao.queryOneObjectList(id);
    }
}
